package com.chenglai.article.controller;

import com.chenglai.article.pojo.ArticleCategory;
import com.chenglai.article.pojo.ArticleInfo;
import com.chenglai.article.service.ArticleCategoryService;
import com.chenglai.commonutils.common.Result;
import com.chenglai.commonutils.common.StatusCode;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 类描述：文章分类
 *
 * @author rjh
 * @date 2023/11/15 10:01
 */
@RestController
@RequestMapping("/articleCategory/")
public class ArticleCategoryController {

    @Resource
    private ArticleCategoryService articleCategoryService;


    /**
     * 获取分类列表
     *
     * @param page   页码
     * @param size   数量
     * @param shopId 门店id
     * @return
     */
    @PostMapping("getArticleCateGoryList")
    @ApiOperation(value = "获取视频列表")
    public Result getArticleCateGoryList(Integer page, Integer size, Integer shopId) {
        try {
            PageInfo pageInfo = articleCategoryService.getArticleCateGoryList(page, size, shopId);
            return new Result(true, StatusCode.OK, "操作成功", pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 添加/修改文章分类
     *
     * @param articleCategory 文章分类实体类
     */
    @PostMapping("editArticleCategory")
    @ApiOperation(value = "添加/修改文章分类")
    public Result editArticleCategory(ArticleCategory articleCategory) {
        try {
            articleCategoryService.editArticleCategory(articleCategory);
            return new Result(true, StatusCode.OK, "操作成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 删除文章分类
     *
     * @param categoryId 文章分类ID
     */
    @PostMapping("delArticleCategory")
    @ApiOperation(value = "删除文章分类")
    public Result delArticleCategory(Integer categoryId) {
        try {
            Map<String,Object> data = articleCategoryService.delArticleCategory(categoryId);
            return new Result(true, StatusCode.OK, "操作成功",data);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "操作失败");
        }
    }

    /**
     * 文章分类详情
     *
     * @param categoryId 文章分类ID
     */
    @PostMapping("detail")
    @ApiOperation(value = "文章分类详情")
    public Result categoryDetail(Integer categoryId) {
        try {
            ArticleCategory detail = articleCategoryService.categoryDetail(categoryId);
            return new Result(true, StatusCode.OK, "查询成功", detail);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

    /**
     * 根据文章分类查询文章集合
     *
     * @param categoryId 文章分类ID
     */
    @PostMapping("articleList")
    @ApiOperation(value = "根据文章分类查询文章集合")
    public Result queryArticleListByCategoryId(Integer categoryId) {
        try {
            List<ArticleInfo> list = articleCategoryService.queryArticleListByCategoryId(categoryId);
            return new Result(true, StatusCode.OK, "查询成功", list);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

    @GetMapping("test")
    public Result test() {
        try {
            return new Result(true, StatusCode.OK, "查询成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, StatusCode.ERROR, "查询失败");
        }
    }

}
